<template> 
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <!-- <el-button size="mini" class="btn-add" :disabled="addvideo" @click="handleAdd()">添加分销</el-button> -->
      <el-button size="mini" class="btn-add" @click="handleAdd()">添加分销</el-button>
    </el-card>
    <div class="table-container">
      <el-table ref="homeAdvertiseTable"
                :data="list"
                style="width: 100%;"
                @selection-change="handleSelectionChange"
                v-loading="listLoading" border>
        <el-table-column type="selection" width="60" align="center"></el-table-column>

        <el-table-column label="编号" width="120" align="center">
          <template slot-scope="scope">{{scope.row.id}}</template>
        </el-table-column>


        <el-table-column label="二级直推(一级抽取佣金比例)"   align="center">
          <template slot-scope="scope">{{scope.row.firstTakeSecond}}</template>
        </el-table-column>
        <el-table-column label="三级直推(一级抽取佣金比例)"   align="center">
          <template slot-scope="scope">{{scope.row.firstTakeThirdly}}</template>
        </el-table-column>
        <el-table-column label="三级直推(二级抽取佣金比例)"  align="center">
          <template slot-scope="scope">{{scope.row.secondTakeThirdly}}</template>
        </el-table-column>

         <el-table-column label="启用" width="120" align="center">
          <template slot-scope="scope">
            <el-switch
              @change="handleUpdateStatus(scope.$index, scope.row)"
              :active-value="0"
              :inactive-value="1"
              v-model="scope.row.status">
            </el-switch>
          </template>
        </el-table-column>


        <el-table-column label="修改时间" align="center">
          <template slot-scope="scope">
            <p>{{scope.row.updateTime | formatTime}}</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button size="mini"
                       type="text"
                       @click="handleUpdate(scope.$index, scope.row)">编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
  import {distributionList,updatadisList} from '@/api/homeAdvertise';
  import {formatDate} from '@/utils/date';
  const defaultListQuery = {
    pageNum: 1,
    pageSize: 5,
    name: null,
    type: null,
    endTime:null
  };
  export default {
    name: 'homeAdvertiseList',
    data() {
      return {
        listQuery: Object.assign({}, defaultListQuery),
        list: null,
        total: null,
        listLoading: false,
        multipleSelection: [],
        operateType: null,
        addvideo:false,
      }
    },
    created() {
      this.getList();
    },
    filters:{
      formatTime(time){
        if(time==null||time===''){
          return 'N/A';
        }
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      },
    },
    methods: {
      
      handleSelectionChange(val){
        this.multipleSelection = val;
      },
      handleAdd(){
        this.$router.push({path: '/sms/adddistribution'})
      },
      handleUpdate(index,row){
        this.$router.push({path: '/sms/updatedistribution', query: {id: row.id}})
      },
      getList() {
        this.listLoading = true;
        distributionList(this.listQuery).then(response => {
          this.listLoading = false;
          console.log(response.data)
          this.list = []
          this.list.push(response.data)

          this.addvideo = false
          if(response.data){
            this.addvideo = true
          }
        })
      },
      handleUpdateStatus(index,row){
        console.log(row.status)
        console.log(this.list[0])
        this.$confirm('是否要修改启用状态?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          updatadisList(this.list[0]).then(response => {
            this.getList();
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
          });
        }).catch(() => {
          this.$message({
            type: 'success',
            message: '已取消操作!'
          });
          this.getList();
        });
      },
    }
  }
</script>
<style scoped>
  .input-width {
    width: 203px;
  }
</style>


